﻿using UnityEngine;
using System.Collections;

public class HealthPickup : MonoBehaviour 
{
	public float healAmount = 10;
	public float healthMax;
	public bool IAmPlayer;
	public GUIText HP;
	public GUIText Ammo;

	public float currentHealth;

	void Start()
	{
		currentHealth = healthMax;
	}

	void Update()
	{
		if(HP != null && Ammo != null)
		{
			HP.text = "HP " + currentHealth;
			Ammo.text = "Ammo : a fuck load";
		}
	}

	void OnTriggerEnter(Collider other)
	{
		if(other.CompareTag("Health") && IAmPlayer)
		{
			GetHealth(healAmount);
			Destroy(other.gameObject);
		}
		else if(other.CompareTag("Trophy") && IAmPlayer)
		{
			Application.LoadLevel("End Screen");
		}
	}

	public void TakeDamage(float damage)
	{
		if(currentHealth > 0.0f)
		{
			currentHealth -= damage;
		}
	}
	
	public void GetHealth(float heal)
	{
		currentHealth += heal;
		
		if(currentHealth > healthMax)
		{
			currentHealth = healthMax;
		}
	}
	
	public bool IsAlive()
	{
		return (currentHealth > 0.0f);
	}
}
